﻿
Imports std
Imports centrosphere

Public Class jobtypesDistributor
    Inherits distributor

    Private Enum queues As Byte
        simpleJob = 0
        storageJob
        operationJob
    End Enum

    Private Function [select](ByVal i As ijob) As UInt32
        If istype(Of simpleJob)(i) Then
            Return queues.simpleJob
        ElseIf istype(Of storageJob)(i) Then
            Return queues.storageJob
        ElseIf istype(Of operationJob)(i) Then
            Return queues.operationJob
        Else
            assert(False)
            Return Nothing
        End If
    End Function

    Protected Overrides Function aggregate(ByVal targetJobs() As indexedJob, ByVal inputJob As ijob) As Boolean
        Return unique_aggregate(targetJobs, inputJob)
    End Function

    Protected Overrides Function distribute(ByVal inputJob As ijob,
                                            ByVal targetJobs As vector(Of pair(Of UInt32, ijob)),
                                            ByRef waitall As Boolean) As Boolean
        Return select_distribute(inputJob, targetJobs, waitall, AddressOf [select])
    End Function
End Class
